﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using ECCSystem.DataAccess;
using ECCSystem.EntityClass;
using ECCSystem.BizRule;
using ECC_EXT_DAO.Dao;
using ECC_EXT_Entity;
using ECC_EXT_HttpLib;
using ECC_EXT_WindowControlLib;

namespace ECCSystem
{
    public partial class frm_Ext_Edit : Form
    {
        private SeasonTextDao _seasonTextDao; 

        public int type { get; set; }
        public EmailTempletEntity objEmailTempletEntity { get; set; }
        private MailContentDetailsDao _mailContentDetailsDao;
        private OFFAnnotationDao _offAnnotationDao;

        private IEInstanceResult pIeInstanceResult = null;
        private frm_Ext_GetAccountInfo _frmExtGetAccountInfo;
        private AccountInfo pAccountInfo = null;
        private frmTemplateImportAndInput _TemplateForm = null;

        private MailParagraghDao _mailParagraghDao;
        private MailParagraghContentDao _mailParagraghContentDao;
        private bool RadiobuttonFlg = false;
        
        public frm_Ext_Edit(frmTemplateImportAndInput pTemplateForm)
        {
            InitializeComponent();
            _seasonTextDao = new SeasonTextDao();
            _mailContentDetailsDao = new MailContentDetailsDao();
            _offAnnotationDao = new OFFAnnotationDao();

            _TemplateForm = pTemplateForm;

            _mailParagraghDao = new MailParagraghDao();
            _mailParagraghContentDao = new MailParagraghContentDao();
        }

        private void frm_Ext_Edit_Load(object sender, EventArgs e)
        {
            //MailMatch Sync
            try
            {
                this.MailSyncInit();
                
                //
                this.radioBtnInit();
                this.DetailsInit();

            }
            catch (Exception ex)
            {
                ExtUtility.logger.Debug(ex.Message);

                Exception exception = ex;
                while (exception.InnerException != null)
                {
                    ExtUtility.logger.Debug(exception.InnerException.Message);
                    exception = exception.InnerException;
                }

                ExtUtility.logger.Debug(ex.StackTrace);
                throw ex;

            }


            this.label_SystemMail.ForeColor = Color.DeepPink;
            this.label_MPS.ForeColor = Color.DeepPink;
            this.groupBox2.ForeColor = Color.DeepPink;
        }
        #region Mail
        private void MailSyncInit()
        {
            this.pIeInstanceResult = new IEInstance().GetInfoRes();
            if (this.pIeInstanceResult != null)
            {
                this.SetMailInfoView();

                new Thread(new ThreadStart(ListenWebBrowserThread)).Start();
                _frmExtGetAccountInfo = new frm_Ext_GetAccountInfo(this.pIeInstanceResult.MailQuestion);
                //_frmExtGetAccountInfo = new frm_Ext_GetAccountInfo(this.richTextBox_MailQuestion.Text);


                this.MerchandiseNamesInit();
            }
        }

        #region AccountInfo

        delegate void FormDelegate () ;
        private void ListenWebBrowserThread()
        {
            while (_frmExtGetAccountInfo == null || _frmExtGetAccountInfo.resAccountInfo == null)
            {
                Thread.Sleep(500);
            }
            this.Invoke(new FormDelegate(ViewAccountRes));

        }

        private void ViewAccountRes()
        {


            this.pAccountInfo = _frmExtGetAccountInfo.resAccountInfo;

            this.label_Name1.Text = _frmExtGetAccountInfo.resAccountInfo.checkNo_Name;
            this.label_Name2.Text = _frmExtGetAccountInfo.resAccountInfo.checkMail_Name;
            this.label_Name3.Text = _frmExtGetAccountInfo.resAccountInfo.checkMail2_Name;

            this.label_No1.Text = _frmExtGetAccountInfo.resAccountInfo.checkNo_No;
            this.label_No2.Text = _frmExtGetAccountInfo.resAccountInfo.checkMail_No;
            this.label_No3.Text = _frmExtGetAccountInfo.resAccountInfo.checkMail2_No;

            this.label_MatchRes.Text = _frmExtGetAccountInfo.resAccountInfo.MatchRes;

            if(_frmExtGetAccountInfo.resAccountInfo.isMatch)
            {
                this.textBox_MailMemo.Text += ("\n" + _frmExtGetAccountInfo.resAccountInfo.checkNo_strCopy);
                this.groupBox2.Text = _frmExtGetAccountInfo.resAccountInfo.DeviceTarget;
                this.label_MPS.Text = _frmExtGetAccountInfo.resAccountInfo.MPS;
                this.label_SystemMail.Text = _frmExtGetAccountInfo.resAccountInfo.HasSystem;
            }
            

            _frmExtGetAccountInfo.Dispose();
        }
        #endregion

        private void SetMailInfoView()
        {
            this.richTextBox_MailQuestion.Text =
                    this.pIeInstanceResult.MailQuestion;

                this.textBox_MailMemo.Text =
                    this.pIeInstanceResult.MailMemo;

        }


        #endregion

        #region Details
        public void TemplateInit()
        {
            if(!this.checkBox_LockAnswer.Checked)
            {
                this.radioBtnInit();
                this.DetailsInit();
            }

        }

        private void DetailsInit()
        {

            MailContentDetailsEntity _mailContentDetailsEntity = new MailContentDetailsEntity();

            _mailContentDetailsEntity.EmailContentKeyID = this.objEmailTempletEntity.ContentKeyID;
            _mailContentDetailsEntity.Type = this.type;

            IList<MailContentDetailsEntity> listMailContentDetailsEntity =
            _mailContentDetailsDao
            .Search(_mailContentDetailsEntity);
               

            MailContentDetailsEntity _entity = new MailContentDetailsEntity();
            _entity.ID = -1;
            _entity.Name = "";

            //
            this.comboBox_Details.Items.Clear();
            this.comboBox_Details.Items.Add(_entity);
            foreach (var mailContentDetailsEntity in listMailContentDetailsEntity)
            {
                this.comboBox_Details.Items.Add(mailContentDetailsEntity);
            }

            this.comboBox_Details.DisplayMember = "Name";
            this.comboBox_Details.ValueMember = "Id";
            this.comboBox_Details.Text = "";
            //
            this.SetContentBox();

        }

        private void SetContentBox()
        {

            if (this.pIeInstanceResult != null
                &&!string.IsNullOrEmpty(this.pIeInstanceResult.MailAnswer))
            {
                this.richTextBox_MailAnwser.Text =
                    this.pIeInstanceResult.MailAnswer;
            }else
            {
                if (this.type == 0)
                    this.richTextBox_MailAnwser.Text = this.objEmailTempletEntity.ToteContent;
                else if (this.type == 1)
                    this.richTextBox_MailAnwser.Text = this.objEmailTempletEntity.PcContent;
            }
            
        }
        #endregion

        private void btn_SeasonText_Header_Click(object sender, EventArgs e)
        {
            SeasonTextEntity _seasonTextEntity =
            _seasonTextDao.GetById(1);
            this.richTextBox_MailAnwser.Text =
            this.richTextBox_MailAnwser.Text.Insert(this.start_selection, _seasonTextEntity.SeasonText);
        }

        private void btn_SeasonText_Footer_Click(object sender, EventArgs e)
        {
            SeasonTextEntity _seasonTextEntity =
            _seasonTextDao.GetById(2);
            this.richTextBox_MailAnwser.Text =
            this.richTextBox_MailAnwser.Text.Insert(this.start_selection, _seasonTextEntity.SeasonText);
        }

        private int start_selection = 0;
        private void textBox_MailAnwser_Leave(object sender, EventArgs e)
        {
            start_selection = this.richTextBox_MailAnwser.SelectionStart;
        }

        private void comboBox_Details_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.comboBox_Details.SelectedIndex != 0)
            {
                this.richTextBox_MailAnwser.Text = getItem().Content;
            }
            else
            {
                //this.DetailsInit();
                this.SetContentBox();
            }
        }
        private MailContentDetailsEntity getItem()
        {
            return this.comboBox_Details.SelectedItem as MailContentDetailsEntity;
        }

        public void  SendToMCS()
        {
            if(!this.OffAnnotationFlg
                && this.pIeInstanceResult !=null
                && this.pIeInstanceResult.CategoryFull.Contains("OFF注文"))
            {
                if (DialogResult.Yes == MessageBox.Show("请确认[OFF注文]是否记录！","Confirm",MessageBoxButtons.YesNo))
                    this.btn_OffAnnotation_Click(null,null);
            }

            this.btn_SendToMCS_Click(null, null);   
        }

        private void btn_SendToMCS_Click(object sender, EventArgs e)
        {
            try
            {
                var _IEInstance = new IEInstance();
                if (!this.checkBox_NoAnswer.Checked)
                {
                    if (!_IEInstance.setAnswer(this.richTextBox_MailAnwser.Text))
                    {
                        if (MessageBox.Show("邮件内容未成功设置，确定结束么？", "Confirm", MessageBoxButtons.YesNo) == DialogResult.No)
                            return;
                        //MessageBox.Show("Mail Anwser Set Failed!");
                    }
                }

                if (!_IEInstance.setMemo(this.textBox_MailMemo.Text))
                {
                    if (MessageBox.Show("Memo内容未成功设置，确定结束么？", "Confirm", MessageBoxButtons.YesNo) == DialogResult.No)
                        return;
                    //MessageBox.Show("Mail Memo Set Failed!");
                }

                this._TemplateForm.TopLevel = true;
                OperationControl.ShowMSC();
                this.Close();
            }
            catch (Exception ex)
            {
                ExtUtility.logger.Debug("MailFinishError");
                ExtUtility.logger.Debug(ex.Message);
                ExtUtility.logger.Debug(ex.StackTrace);
            }
            
        }

        private bool OffAnnotationFlg = false;

        private void btn_OffAnnotation_Click(object sender, EventArgs e)
        {
            //Check exist #

            if (this.pIeInstanceResult == null || this.pAccountInfo == null)
                return;

            IList<String> _listMerchandise =
                this.GetOFFAnnotatonList(this.pIeInstanceResult.MailQuestion);
                //this.GetOFFAnnotatonList(this.textBox_MailAnwser.Text);
            if(_listMerchandise.Count == 0)
            {
                MessageBox.Show("未找到记录项！");
                return;
            }

            OFFAnnotationEntity _offAnnotationEntity = new OFFAnnotationEntity();
            _offAnnotationEntity.CaseNo = this.pIeInstanceResult.MailNo;
            //_offAnnotationEntity.FollowUser = ClsCommon.gStrOperatorName;
            _offAnnotationEntity.RecordUser = ClsCommon.gStrOperatorName;
            _offAnnotationEntity.RecordDate = DateTime.Now;
            _offAnnotationEntity.AccountNo = pAccountInfo.idNo;

            _offAnnotationEntity.dicOFFAnnotatonStatus = new DICOFFAnnotatonStatusEntity(0);

            //Need Transation
            _offAnnotationDao.SaveOrUpdate(_offAnnotationEntity);



            MerchandiseDao _merchandiseDao = new MerchandiseDao();
            MerchandiseEntity _merchandiseEntity;

            foreach (var item in _listMerchandise)
            {
                _merchandiseEntity = new MerchandiseEntity();
                _merchandiseEntity.AnnotationID = _offAnnotationEntity.ID;
                _merchandiseEntity.MerchandiseNo = item;

                //_offAnnotationEntity.MerchandiseEntitys.Add(_merchandiseEntity);

                _merchandiseDao.SaveOrUpdate(_merchandiseEntity);
            }

            MessageBox.Show("记录完成！");
            OffAnnotationFlg = true;
        }

        private IList<String> GetOFFAnnotatonList(String str)
        {
            String tmpstr = "";
            int tmpidx = -1;

            IList<String> _list = new List<string>();
            Regex rg = new Regex("\\d{4}-\\d{5}-[A-Z]-");

            //Type1
            if (str.Contains("＜申込番号＞") 
                    || str.Contains("申込番号") 
                    || str.Contains("申込み商品")
                    || str.Contains("商品情報"))
            {
                MatchCollection mc =
                rg.Matches(str);
                
                foreach (Match item in mc)
                {
                    tmpstr = str.Substring(item.Index);
                    IList<int> checkList = new List<int>();

                    checkList.Add(tmpstr.IndexOf(" "));// half space
                    checkList.Add(tmpstr.IndexOf("　"));// full space
                    checkList.Add(tmpstr.IndexOf("\r"));// change line
                    checkList.Add(tmpstr.IndexOf("\n"));// change line
                    //默认不会以商品号为整段结尾

                    tmpidx = this.GetMin(checkList);

                    if (tmpidx == int.MaxValue)
                        continue;//该条记录没能分割，被遗漏

                    _list.Add(tmpstr
                        .Substring(0, tmpidx > item.Index ? tmpidx - item.Index : tmpidx)
                            .Replace("-", ""));

                }

            }

            return _list;
        }

        private int GetMin(IList<int> list )
        {
            int tmp = int.MaxValue;
            foreach (var i in list)
            {
                if (i != -1 && i < tmp)
                    tmp = i;
            }

            return tmp;
        }

        private void btn_OffCategory_Click(object sender, EventArgs e)
        {

            if (this.pIeInstanceResult == null || this.pAccountInfo == null)
                return;

            IList<String> _listCategory =
                //this.GetOFFCategoryList(this.textBox_MailAnwser.Text);
                //this.GetOFFCategoryList(this.textBox_MailQuestion.Text);
                this.GetOFFCategoryList(this.pIeInstanceResult.MailQuestion);


            if (_listCategory.Count == 0)
            {
                MessageBox.Show("未找到记录项！");
                return;
            }

            OFFCategoryEntity _offCategoryEntity = new OFFCategoryEntity(); ;
            DICOFFCategoryDao _dicoffCategoryDao = new DICOFFCategoryDao();
            OFFCategoryDao _offCategoryDao = new OFFCategoryDao();
            IList<DICOFFCategoryEntity> _sublist = new List<DICOFFCategoryEntity>();
            //IList<DICOFFCategoryEntity> _dicoffCategoryEntities =
            //_dicoffCategoryDao.Search();
            String tmpStr = "";
            foreach (var item in _listCategory)
            {
                int tmpIdx = item.IndexOf("(");
                if (tmpIdx == -1)
                    tmpStr = item;
                else
                    tmpStr = item.Substring(0, tmpIdx);

                IList<DICOFFCategoryEntity> _list =
                    _dicoffCategoryDao.GetByName(tmpStr);
                if (_list.Count == 0)
                {
                    MessageBox.Show("未找到对应的项目[" + item + "]记录失败！");
                    return;
                }
                _sublist.Add(_list[0]);
            }

            //_offCategoryEntity.CaseNo = "1235";
            _offCategoryEntity.CaseNo = this.pIeInstanceResult.MailNo;

            //_offCategoryEntity.AccountNo = "234";
            _offCategoryEntity.AccountNo = this.pAccountInfo.idNo;

            _offCategoryEntity.RecordUser = ClsCommon.gStrOperatorName;
            _offCategoryEntity.RecordDate = DateTime.Now;

            _offCategoryDao.SaveOrUpdate(_offCategoryEntity);


            OFFCategoryItemsDao _offCategoryItemsDao = new OFFCategoryItemsDao();
            OFFCategoryItemsEntity _offCategoryItemsEntity;
            foreach (var item in _sublist)
            {
                _offCategoryItemsEntity = new OFFCategoryItemsEntity();
                _offCategoryItemsEntity.CategoryID = _offCategoryEntity.Id;
                _offCategoryItemsEntity.DICCategory = item;
                _offCategoryItemsDao.SaveOrUpdate(_offCategoryItemsEntity); 
            }


            MessageBox.Show("记录完成！");
        }

        private IList<String> GetOFFCategoryList(String str)
        {
            IList<String> _list = new List<String>();
            String tmpstr = "";
            int startIdx = 0;
            int endIdx = 0;
            String[] Strs;
            if (str.Contains("----ご請求内容"))
            {
                startIdx = str.IndexOf("----ご請求内容");
                endIdx = str.IndexOf("-----------------------------------------------------------------");

                tmpstr = str.Substring(startIdx, endIdx - startIdx);

                Strs = tmpstr.Split('\n');

                //Strs = Strs[1].Split('　');

                for (var i = 2; i + 2 < Strs.Length; i++)
                {
                    Strs[i] =
                        Strs[i].Trim('　').Trim(' ');
                    endIdx =
                        Strs[i].IndexOf('　');

                    _list.Add(Strs[i].Substring(0, endIdx));
                }
            }

            return _list;
        }

        private void btn_MerchandiseSearchOnline_Click(object sender, EventArgs e)
        {
            //if (this.pIeInstanceResult == null || this.pAccountInfo == null)
            //    return;

            IList<String> _listMerchandise =
                //this.GetOFFAnnotatonList(this.pIeInstanceResult.MailQuestion);
                this.GetOFFAnnotatonList(this.richTextBox_MailQuestion.Text);
                //this.GetOFFAnnotatonList(this.richTextBox_MailAnwser.Text);
            if (_listMerchandise.Count == 0)
            {
                MessageBox.Show("未找到！");
                return;
            }

            frm_Ext_MerchandiseList _frm = new frm_Ext_MerchandiseList(_listMerchandise);

            this.Hide();
            _frm.ShowDialog();
            this.Show();

        }

        private void btn_GetMerchandiseNames_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(MerchandiseNames);
            MessageBox.Show("クリップボードにコピーしました。\r\n\r\n" + MerchandiseNames);

        }

        private void MerchandiseNamesInit()
        {
            this.btn_GetMerchandiseNames.Enabled = false;

            IList<String> _listMerchandise =
                this.GetOFFAnnotatonList(this.pIeInstanceResult.MailQuestion);

            if (_listMerchandise.Count == 0)
                return;

            new Thread(new ParameterizedThreadStart(GetMerchandiseNamesOnline)).Start(_listMerchandise);
        }

        private String MerchandiseNames = "";
        private void GetMerchandiseNamesOnline(Object obj)
        {
            IList<String> input = (IList<String>) obj;
            string tmpstr = "";
            try
            {
                foreach (var MerchandiseNo in input)
                {
                    tmpstr =
                    SearchMerchandiseName.GetName(MerchandiseNo);


                    MerchandiseNames +=
                        //MerchandiseNo;
                        MerchandiseNo.Substring(0, 4) + "-" + MerchandiseNo.Substring(4,5) + "-" +
                        MerchandiseNo.Substring(9, 1) + "-" + MerchandiseNo.Substring(10);

                    MerchandiseNames += "：";
                    MerchandiseNames += tmpstr;
                    MerchandiseNames += "\r\n";
                }
            }
            catch (Exception ex)
            {

                this.Invoke(new FormDelegate(
                delegate()
                    {
                        MessageBox.Show(ex.Message);
                    }));
            }


            this.Invoke(new FormDelegate(
                delegate() { 
                    this.btn_GetMerchandiseNames.Enabled = true;
                }));
        }

        private void btn_AcountNo_Click(object sender, EventArgs e)
        {
            if(this.pAccountInfo != null)
            {
                Clipboard.SetText(this.pAccountInfo.idNo == null ? "" : this.pAccountInfo.idNo);
                MessageBox.Show("顧客番号にコピーしました。\r\n\r\n" + this.pAccountInfo.idNo);
            }else
            {
                MessageBox.Show("未取得顧客番号!");
            }

        }

        private void btn_ChangeTemplate_Click(object sender, EventArgs e)
        {
            this.TopLevel =false;
            this._TemplateForm.TopLevel = true;
        }

        private void ParagraghInit()
        {
            this.dataGridView1.Rows.Clear();
            
            var _list = this._mailParagraghDao.Search(this.objEmailTempletEntity.ContentKeyID, this.type);
            foreach (var mailParagraghEntity in _list)
            {
                this.dataGridView1.Rows.Add(mailParagraghEntity.Name, "", mailParagraghEntity.ID, "");
            }
            
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
                return;
            if(e.ColumnIndex == 0)
            {
                string tmpid =
                    this.dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();

                var _list =
                    this._mailParagraghContentDao.Search(long.Parse(tmpid));

                MailParagraghContentEntity _entity = new MailParagraghContentEntity();
                _entity.ID = 0;
                _entity.Name = "";
                _entity.Content = "";

                _list.Insert(0,_entity);

                this.comboBox_Paragragh.DataSource = _list;
                this.comboBox_Paragragh.DisplayMember = "Name";
                this.comboBox_Paragragh.ValueMember = "ID";
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if(this.checkBox1.Checked)
            {
                this.comboBox_Paragragh.Enabled = true;
                this.dataGridView1.Enabled = true;
                this.ParagraghInit();
            }else
            {
                this.comboBox_Paragragh.Enabled = false;
                this.dataGridView1.Enabled = false;
            }
        }

        private void comboBox_Paragragh_SelectedIndexChanged(object sender, EventArgs e)
        {
            var item =
                this.comboBox_Paragragh.SelectedItem as MailParagraghContentEntity;



            if(item != null
                && this.dataGridView1.SelectedCells.Count != 0)
            {
                int rowIndex =
                    this.dataGridView1.SelectedCells[0].RowIndex;

                this.dataGridView1.Rows[rowIndex].Cells[1].Value = item.Name;
                this.dataGridView1.Rows[rowIndex].Cells[3].Value = item.Content;

                this.SetParagraghCombineText();


            }
        }

        private void SetParagraghCombineText()
        {
            string tmpstr = "";
            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                if(string.IsNullOrEmpty(row.Cells[3].Value.ToString()))
                    continue;

                tmpstr += "\r\n";
                tmpstr += row.Cells[3].Value;

            }

            this.richTextBox_MailAnwser.Text = tmpstr.TrimStart('\r').TrimStart('\n');

        }

        private void btn_CommunicateText_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(this._TemplateForm.Get_txtContent());
        }

        private void richTextBox_MailQuestion_TextChanged(object sender, EventArgs e)
        {
            if(this.pIeInstanceResult != null
                && !this.pIeInstanceResult.MailQuestion.Equals(this.richTextBox_MailQuestion.Text))
            {
                this.richTextBox_MailQuestion.Text = this.pIeInstanceResult.MailQuestion;
            }
        }

        private void frm_Ext_Edit_KeyDown(object sender, KeyEventArgs e)
        {
            //shift+t,用于应页面与テンプレート之间的转换
            if (e.Alt && e.KeyCode == Keys.T)
            {
                this.btn_ChangeTemplate_Click(null,null);
                return;
            }

            //shift+n,无回答(No Answer）
            if (e.Alt && e.KeyCode == Keys.N)
            {
                
                this.checkBox_NoAnswer.Checked = !this.checkBox_NoAnswer.Checked;
                return;
            }

            //caps lock,固定模板（Lock Answer）
            if (e.Alt && e.KeyCode == Keys.L)
            {
                this.checkBox_LockAnswer.Checked = !this.checkBox_LockAnswer.Checked;
                return;
            }


            //shift+k,交渉記録
            if (e.Alt && e.KeyCode == Keys.K)
            {
                this.btn_CommunicateText_Click(null,null);
                return;
            }

            //shift+enter,终了
            if(e.Alt && e.KeyCode == Keys.Enter)
            {
                _TemplateForm.EntryInputAction(Keys.Enter);
                return;
            }

            //shift+back space,转送
            if (e.Alt && e.KeyCode == Keys.Back)
            {
                _TemplateForm.EntryInputAction(Keys.Back);
                return;
            }

            //shift+b	copy会员番号
            if (e.Alt && e.KeyCode == Keys.B)
            {
                this.btn_AcountNo_Click(null,null);
                return;
            }
        }

        private void radioBtnInit()
        {
            this.RadiobuttonFlg = true;
            if (0 == this.type)
                this.radioButton_KT.Select();
            if (1 == this.type)
                this.radioButton_PC.Select();
        }

        private void radioButton_KT_CheckedChanged(object sender, EventArgs e)
        {
            if(this.radioButton_KT.Checked)
                this.type = 0;

            if (!this.RadiobuttonFlg)
                this.DetailsInit();
            else
                this.RadiobuttonFlg = false;
        }

        private void radioButton_PC_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioButton_PC.Checked)
                this.type = 1;

            if (!this.RadiobuttonFlg)
                this.DetailsInit();
            else
                this.RadiobuttonFlg = false;
        }

        private void button_replymail_Click(object sender, EventArgs e)
        {
            var form = new frm_Ext_RelyPaper();

            form.MailNo = this.pIeInstanceResult.MailNo;

            form.ShowDialog();
        }

    }
}
